package afcp.alumni.model.db;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.NotPersistent;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import afcp.alumni.model.base.DatastoreEntity;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

@PersistenceCapable
public class Defect implements DatastoreEntity {
 
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key key;
	@Persistent
	private String theDescription;
	@Persistent
	private int criticity;

	@Override
	public String getId() {
		if (key != null) {
			return KeyFactory.keyToString(key);
		} else {
			return null;
		}
	}

	@Override
	public Key getKey() {
		return key;
	}

	@Override
	public void setKeyWithAncestor(Key ancestorKey) {
		// nothing. No ancestor and automatic id generation.
	}

	public String getDescription() {
		return theDescription;
	}

	public void setDescription(String description) {
		this.theDescription = description;
	}

	public int getCriticity() {
		return criticity;
	}

	public void setCriticity(int criticity) {
		this.criticity = criticity;
	}
	
	public String getCriticityLabel() {
		return criticities[criticity];
	}
	
	@NotPersistent
	private static String[] criticities = new String[]{"Critical", "Major", "Minor"};
//	private Criticity[] criticities = new Criticity[]{new Criticity(2, "Minor"), new Criticity(1, "Major"), new Criticity(0, "Critical")};
	
	public static String[] getCriticities() {
		return criticities;
	}
	
	public static class Criticity {
		private int id;
		private String label;
		public int getId() {
			return id;
		}
		public void setId(int id) {
			this.id = id;
		}
		public String getLabel() {
			return label;
		}
		public void setLabel(String label) {
			this.label = label;
		}
		public Criticity(int id, String label) {
			super();
			this.id = id;
			this.label = label;
		}
	}
	
	@Override
	public String toString() {
		return getId();
	}

}
